<?php

use yii\db\Migration;

class m160507_065818_update_htf_user extends Migration
{
    const TBL_NAME = '{{%user}}';
    public function up()
    {
        $sql = "DROP TABLE IF EXISTS ".self::TBL_NAME.";
            CREATE TABLE ".self::TBL_NAME." (
              `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
              `union_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '注册用户唯一标识',
              `username` char(30) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '手机号',
              `auth_key` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '权限',
              `password_hash` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '密码',
              `password_reset_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '密码重置令牌',
              `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '邮箱',
              `status` smallint(6) DEFAULT '10',
              `level` varchar(255) COLLATE utf8_unicode_ci DEFAULT '1' COMMENT '用户等级',
              `created_at` char(25) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '注册时间',
              `updated_at` char(25) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '更新时间',
              `logout_time` char(25) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '退出时间',
              `mac_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '设备号 唯一区分标识',
              `address` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '地址',
              `sex` tinyint(2) unsigned DEFAULT NULL COMMENT '性别  保密(0) 男(1) 女(2) ',
              `age` int(3) unsigned DEFAULT NULL COMMENT '年龄',
              `nic_thumb` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '用户头像',
              `nic_name` char(30) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '昵称',
              `htf_money` int(10) DEFAULT '0' COMMENT '发币',
              `best_startPage` int(10) DEFAULT '0' COMMENT '推荐起始文章id',
              `new_startPage` int(10) DEFAULT '0' COMMENT '更新起始文章id',
              `history_startPage` int(10) DEFAULT '0' COMMENT '历史访问起始文章id',
              `tab` text COLLATE utf8_unicode_ci COMMENT '用户文章类别',
              `verify_code` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '验证码',
              `verify_time` char(25) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '验证码生成时间',
              `is_share` tinyint(2) DEFAULT '2' COMMENT '是否已经分享；1已经分享2没有分享',
              PRIMARY KEY (`id`),
              UNIQUE KEY `mac_id` (`mac_id`),
              UNIQUE KEY `username` (`username`),
              KEY `email` (`email`) USING BTREE,
              KEY `union_id` (`union_id`) USING BTREE
            ) ENGINE=InnoDB AUTO_INCREMENT=305 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
            INSERT INTO ".self::TBL_NAME." VALUES ('1', 'admin', 'admin', null, '$2y$13$42rHEptJCVU4l7Ffdc8.a.pj/zZahYEB9DeoIqSXcoin8WgV5dIgq', null, null, '10', '1', '1459955596', '1459955596', null, 'htf_3030', null, null, null, null, 'htf_3030', '0', '0', '0', '0', null, null, null, '2');";

        $this->execute($sql);
    }

    public function down()
    {
        echo "m160507_065818_update_htf_user cannot be reverted.\n";

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
